package org.javaapps.common.dao;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;

public interface IBaseDao<M extends java.io.Serializable, PK extends java.io.Serializable> {
    
    public PK save(M model);

    public void saveOrUpdate(M model);
    
    public void update(M model);
    
    public void merge(M model);

    public void delete(PK id);

    public void deleteObject(M model);

    public M get(PK id);
    
    public int countAll();

    public List<M> listAll();

    public List<M> listAll(int pn, int pageSize);
    
    public List<M> pre(PK pk, int pn, int pageSize);
    public List<M> next(PK pk, int pn, int pageSize);
    
    boolean exists(PK id);
    
    public void flush();
    
    public void clear();

    /**
     * with in or not in query
     * @param hql
     * @param start
     * @param length
     * @param map
     * @param paramlist
     * @return
     */
    public <T> List<T> listHql(final String hql,final int start, final int length, final Map<String, Collection<?>> map, final Object... paramlist);
    public <T> List<T> list(DetachedCriteria criteria);
    public <T> List<T> list(DetachedCriteria criteria, int pn, int pageSize);
    public <T> List<T> listeq(Class<?> clazz, M model, int pn, int pageSize);
    public <T> List<T> listlike(Class<?> clazz, M model, int pn, int pageSize);
}
